//
// AppDelegate.m
// LBXDownLoad
//
// Created by lbxia on 2021/4/20
//
//
    

#import "AppDelegate.h"
#import "MainViewController.h"
#import "LBXDownLoadManager.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    
    UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:[[MainViewController alloc]init]];
    self.window.rootViewController = navi;
    
    [self.window makeKeyAndVisible];
    
    return YES;
}


//- (void)applicationDidEnterBackground:(UIApplication *)application
//{
//    //调用这句,防止应用在进入后台后所有任务被终止
////        [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
////        }];
//}

//后台挂起下载完成回调
- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler {
    // 你必须重新建立一个后台 seesion 的实例
    // 否则 NSURLSessionDownloadDelegate 和 NSURLSessionDelegate 方法会因为
    // 没有 对 session 的 delegate 设定而不会被调用。参见上面的 backgroundURLSession
    NSURLSession *backgroundSession = [LBXDownLoadManager sharedManager].session;
    
    NSLog(@"handleEventsForBackgroundURLSession Rejoining session with identifier %@ %@", identifier, backgroundSession);
    
    // 保存 completion handler 以在处理 session 事件后更新 UI
//    [self addCompletionHandler:completionHandler forSession:identifier];
}



@end
